// @ts-nocheck
import { defineStore } from "pinia";
import { SET_USERINFO, GET_USERINFO, DEL_USERINFO } from "../storage";
import { userInfoInt } from "./type";

const loginStore = defineStore("login", {
  state: (): userInfoInt => {
    return {
      // 用户信息
      userInfo: JSON.parse(GET_USERINFO() as string) || {},
    };
  },
  getters: {},
  actions: {
    // 登录
    async login(userInfo: userInfoInt) {
      // console.log("res", userInfo);
      this.userInfo = userInfo;
      SET_USERINFO(JSON.stringify(this.userInfo));
    },
    // 退出登录
    loginOut() {
      DEL_USERINFO();
      this.userInfo = {
        name: "",
        token: "",
      };
    },
  },
});

export default loginStore;
